<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title> </title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
[#include "/admin/include/head.htm"/]
<link href="${base}/resource/thirdparty/zTree/css/demo.css" rel="stylesheet" type="text/css" />
<link href="${base}/resource/thirdparty/zTree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${base}/resource/thirdparty/zTree/jquery.ztree.core-3.4.js"></script>
<script type="text/javascript" src="${base}/resource/thirdparty/zTree/jquery.ztree.excheck-3.4.js"></script>
<script type="text/javascript" src="${base}/resource/thirdparty/zTree/jquery.ztree.exedit-3.4.js"></script>
	
	<script type="text/javascript">
		var zTree1;
		$(function(){
			var mainform = $("#mainform");  
			//表单底部按钮 
		    LG.setFormDefaultBtn(f_cancel, function(){
				f_save(mainform, "b2c_delivery_method_list");
			});
			
			$("#addConfig").click(function(){
				var html = $("<td></td>").append($("#params").html());
				html = $("<tr></tr>").append('<th></th>').append(html);
				$(".inputTable2 tbody").append(html);
			});
			
			zTree1 = $.fn.zTree.init($("#treeDemo"), {
				async: {
					enable: true,
					url: base + "/admin/b2c/deliveryMethod/areaTree.jhtml",
					autoParam: ["id=parentId"]
				},
				check: {
					enable: true,
					chkboxType:{ "Y": "p", "N": "ps" }
				},
				data: {
					simpleData: {
						enable: true
					}
				}
			});
		});
		
		function selectArea(obj){
			var $this = $(obj);
			var value = $this.prev().val();
			var checkeds = value.split(',');
			for(var i = 0; i < checkeds.length;i++){
				if(checkeds[i]){
					var node = zTree1.getNodeByParam('id', checkeds[i]);
					if(node){
						zTree1.checkNode(node,true, true);
					}
				}
			}
			$.ligerDialog.open({
                    target	: $("#areaTree"),
                    buttons	: [{ 
                    	text: '保存', 
                    	onclick: function (i, d) { 
                    		var nodes = zTree1.getCheckedNodes(true);
                    		if(nodes.length == 0){
                    			LG.tip('请选择区域');
                    			return;
                    		}
                    		var display = '';
                    		var hidden = ',';
                    		for(var i = 0;i < nodes.length;i++){
                    			display += nodes[i].name + ',';
                    			hidden += nodes[i].id + ',';
                    		}
                    		$this.val(display.substring(0,display.length-1));
                    		$this.prev().val(hidden);
                    		zTree1.checkAllNodes(false);
                    		d.hide();
                    	}
                    },{ 
                    	text: '关闭', 
                    	onclick: function (i, d) { 
                    		zTree1.checkAllNodes(false);
                    		d.hide();
                    	}
                    }]                                  
               });
		}
	</script>
	
	[#if !deliveryMethod??]
		[#assign isAdd = true /]
	[#else]
		[#assign isEdit = true /] 
	[/#if]
</head>
<body style="padding:10px; ">
	<div id="tabcontainer" style="margin:0; padding:0">
		<form action="[#if isAdd??]save.jhtml[#else]update.jhtml[/#if]" method="post" class="validate" id="mainform">
			[#if !isAdd??]
				<input type="hidden" name="id" value="${(deliveryMethod.id)!''}"/>
			[/#if]
			<table class="inputTable2">
				<tr>
					<th>配送方式名称：</th>				
					<td>
						<input type="text" name="name" value="${(deliveryMethod.name)!}" class="formText {required:true, remote: '${base}/admin/b2c/deliveryMethod/checkName.jhtml?oldName=${(deliveryMethod.name)!}', messages: {remote: '配送方式名称已存在!'}}" />
					</td>
				</tr>
				<tr>
					<th>物流公司：</th>				
					<td>
						<input type="text" name="company" value="${(deliveryMethod.company)!}" class="formText {required:true}" />
					</td>
				</tr>
				<tr>
					<th>编码：</th>				
					<td>
						<input type="text" name="code" value="${(deliveryMethod.code)!}" class="formText {required:true}" />
					</td>
				</tr>
				<tr>
					<th>是否可用：</th>				
					<td>
						[@u.radio name="isAvaliable" list={'true': '是', 'false':'否'}
							value="${((deliveryMethod.isAvaliable)?string('true', 'false'))!'true'}"/]
					</td>
				</tr>
				<tr>
					<th>首重：</th>				
					<td>
						<input type="text" name="firstWeight" value="${(deliveryMethod.firstWeight)!}" class="formText {required:true,number:true}" />
					</td>
				</tr>
				<tr>
					<th>首重价格：</th>				
					<td>
						<input type="text" name="firstPrice" value="${(deliveryMethod.firstPrice)!}" class="formText {required:true,number:true}" />
					</td>
				</tr>
				<tr>
					<th>续重：</th>				
					<td>
						<input type="text" name="continueWeight" value="${(deliveryMethod.continueWeight)!}" class="formText {required:true,number:true}" />
					</td>
				</tr>
				<tr>
					<th>续重价格：</th>				
					<td>
						<input type="text" name="continuePrice" value="${(deliveryMethod.continuePrice)!}" class="formText {required:true,number:true}" />
					</td>
				</tr>
				<tr>
					<th>显示图标：</th>				
					<td>
						<input type="text" name="icon" value="${(deliveryMethod.icon)!}" class="formText" />
					</td>
				</tr>
				<tr>
					<th>排序：</th>				
					<td>
						<input type="text" name="priority" value="${(deliveryMethod.priority)!0}" class="formText {required:true}" />
					</td>
				</tr>
				<tr>
					<th>描述：</th>				
					<td>
						<textarea name="description" cols="50" rows="3" class="formText" >${(deliveryMethod.description)!}</textarea>
					</td>
				</tr>
				<tr>
					<th>区域配置：</th>
					<td>
						<input type="button" value="新增" class="button" id="addConfig"/>
					</td>
				</tr>
				[#if deliveryMethod?? && deliveryMethod.configJson??]
					[#list deliveryMethod.configJson.keySet() as key]
						<tr>
							<th></th>
							<td>
								区域：<input type="hidden" name="area" value="${key}"/>
								<input type="text" onclick="selectArea(this);" readonly="readonly" style="width: 500px;" name="display" value="${deliveryMethod.configJson[key].display}" class="formText {required:true}" />
								首重(kg)：<input type="text" name="fw" class="formText {required:true,number:true}" style="width: 100px;" value="${deliveryMethod.configJson[key].firstWeight}"/>
								首重价格：<input type="text" name="fp" class="formText {required:true,number:true}" style="width: 100px;" value="${deliveryMethod.configJson[key].firstPrice}"/>
								续重(kg)：<input type="text" name="cw" class="formText {required:true,number:true}" style="width: 100px;" value="${deliveryMethod.configJson[key].continueWeight}"/>
								续重价格：<input type="text" name="cp" class="formText {required:true,number:true}" style="width: 100px;" value="${deliveryMethod.configJson[key].continuePrice}"/>
							</td>
						</tr>
					[/#list]
				[/#if]
			</table>
		</form>
	</div>
	<div style="display: none" id="params">
		区域：<input type="hidden" name="area"/>
		<input type="text" onclick="selectArea(this);" readonly="readonly" style="width: 500px;" name="display" class="formText {required:true}" />
		首重(kg)：<input type="text" name="fw" class="formText {required:true,number:true}" style="width: 100px;"/>
		首重价格：<input type="text" name="fp" class="formText {required:true,number:true}" style="width: 100px;"/>
		续重(kg)：<input type="text" name="cw" class="formText {required:true,number:true}" style="width: 100px;"/>
		续重价格：<input type="text" name="cp" class="formText {required:true,number:true}" style="width: 100px;"/>
	</div>
	<div id="areaTree" style="overflow-x:auto;overflow-y:auto;display: none">
		<ul id="treeDemo" class="ztree" style="overflow:hidden;"></ul>
	</div>
</body>
</html>